package com.gome.gop.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 表格数据查询结果
 * 
 * @author wangwenhui
 *
 */
public class SearchResult implements Serializable{

	private static final Logger logger = LoggerFactory.getLogger(SearchResult.class);
	/**
	 * 
	 */
	private static final long serialVersionUID = 5560250265158265243L;

	/**
     * 记录总数
     */
    private int total = 0;

	/**
     * 最大查询记录数
     */
    private int maxRows;

    /**
     * 记录List
     */
    private List<?> rows = new ArrayList<String>();
    
    /**
     * 记录列合计值
     */
    private List<?>	footer = new ArrayList<Map<String, Object>>();
    
    /**
     * 构造函数
     */
    public SearchResult() {
    }

    /**
     * 构造函数
     * 
     * @param total
     *            记录总数
     * @param rows
     *            记录List
     */
    public SearchResult(int total, List<?> rows) {
        this.total = total;
        this.rows = rows;
    }

    /**
     * 获取记录总数 * @return 记录总数
     */
    public int getTotal() {
        return total;
    }

    /**
     * 设置记录总数
     * 
     * @param total
     *            记录总数
     */
    public void setTotal(int total) {
        this.total = total;
    }

    /**
     * 获取记录List
     * 
     * @return 记录List
     */
    public List<?> getRows() {
        return rows;
    }

    /**
     * 设置记录List
     * 
     * @param rows
     *            记录List
     */
    public void setRows(List<?> rows) {
        this.rows = rows;
        
        //监控记录条数  大于1000可能存在问题  
        try {
        	if(rows != null && rows.size() > 1000){
        		StackTraceElement[] trace=Thread.currentThread().getStackTrace();
         		StackTraceElement stack=(StackTraceElement)trace[2];
         		logger.warn("Date = "+ DateTimeUtil.getCurrentDate() + ",记录数:size = " + rows.size() + ",获取上一级调用类class = " + stack.getClassName() + ",上一级调用方法method = "
    					+ stack.getMethodName() + ",获取调用setRows方法所在行数 lineNumber = " + stack.getLineNumber());
        	}
		} catch (Exception e) {
		  //异常不处理 
		}
    }

	/**
	 * @return the maxRows
	 */
	public int getMaxRows() {
		return maxRows;
	}

	/**
	 * @param maxRows the maxRows to set
	 */
	public void setMaxRows(int maxRows) {
		this.maxRows = maxRows;
	}

	public List<?> getFooter() {
		return footer;
	}

	public void setFooter(List<?> footer) {
		this.footer = footer;
	}

	/**
	 * 重写toString
	 */
	@Override
	public String toString() {
		return "SearchResult [total=" + total + ", maxRows=" + maxRows + ", rows=" + rows + ", footer=" + footer + "]";
	}


}
